package com.magalindo8;

import android.content.Context;
import android.content.SharedPreferences;

public class Preferencias {

	private Context context;
	private final String SHARED_PREFS_FILE = "AstPrefs";

	private final String KEY_MONEDAS = "numMonedas";
	private final String KEY_MISILES = "numMisiles";	
	private final String KEY_MAX_ASTEROIDES = "masAsteroides";

	public Preferencias(Context context) {
		this.context = context;
	}

	private SharedPreferences getSettings() {
		return context.getSharedPreferences(SHARED_PREFS_FILE, 0);
	}

	public int getMonedas() {
		return getSettings().getInt(KEY_MONEDAS, 0);
	}

	public void setMonedas(int monedas) {
		SharedPreferences.Editor editor = getSettings().edit();
		editor.putInt(KEY_MONEDAS, monedas);
		editor.commit();
	}
	
	public int getMisiles() {
		return getSettings().getInt(KEY_MISILES, 0);
	}

	public void setMisiles(int misiles) {
		SharedPreferences.Editor editor = getSettings().edit();
		editor.putInt(KEY_MISILES, misiles);
		editor.commit();
	}
	
	public int getMaxAsteroides() {
		return getSettings().getInt(KEY_MAX_ASTEROIDES, 0);
	}

	public void setMaxAsteroides(int maxAsteroides) {
		if (getMaxAsteroides() < maxAsteroides) {
			SharedPreferences.Editor editor = getSettings().edit();
			editor.putInt(KEY_MAX_ASTEROIDES, maxAsteroides);
			editor.commit();
		}
	}
}
